package com.ruoyi.household.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.api.domain.ResidentialQuarters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.household.service.IResidentialQuartersService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 小区CRUDController
 * 
 * @author ruoyi
 * @date 2022-10-01
 */
@RestController
@RequestMapping("/quarters")
public class ResidentialQuartersController extends BaseController
{
    @Autowired
    private IResidentialQuartersService residentialQuartersService;

    /**
     * 查询小区CRUD列表
     */
    @RequiresPermissions("quarters:quarters:list")
    @GetMapping("/list")
    public TableDataInfo list(ResidentialQuarters residentialQuarters)
    {
        startPage();
        List<ResidentialQuarters> list = residentialQuartersService.selectResidentialQuartersList(residentialQuarters);
        return getDataTable(list);
    }

    /**
     * 导出小区CRUD列表
     */
    @RequiresPermissions("quarters:quarters:export")
    @Log(title = "小区CRUD", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ResidentialQuarters residentialQuarters)
    {
        List<ResidentialQuarters> list = residentialQuartersService.selectResidentialQuartersList(residentialQuarters);
        ExcelUtil<ResidentialQuarters> util = new ExcelUtil<ResidentialQuarters>(ResidentialQuarters.class);
        util.exportExcel(response, list, "小区CRUD数据");
    }

    /**
     * 获取小区CRUD详细信息
     */
    @RequiresPermissions("quarters:quarters:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(residentialQuartersService.selectResidentialQuartersById(id));
    }

    /**
     * 新增小区CRUD
     */
    @RequiresPermissions("quarters:quarters:add")
    @Log(title = "小区CRUD", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ResidentialQuarters residentialQuarters)
    {
        return toAjax(residentialQuartersService.insertResidentialQuarters(residentialQuarters));
    }

    /**
     * 修改小区CRUD
     */
    @RequiresPermissions("quarters:quarters:edit")
    @Log(title = "小区CRUD", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ResidentialQuarters residentialQuarters)
    {
        return toAjax(residentialQuartersService.updateResidentialQuarters(residentialQuarters));
    }

    /**
     * 删除小区CRUD
     */
    @RequiresPermissions("quarters:quarters:remove")
    @Log(title = "小区CRUD", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(residentialQuartersService.deleteResidentialQuartersByIds(ids));
    }
}
